package com.ys.nms.module.business.service.portsVlans;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.ys.nms.module.business.controller.admin.portsVlans.vo.*;
import com.ys.nms.module.business.dal.dataobject.portsVlans.PortsVlansDO;
import com.ys.nms.framework.common.pojo.PageResult;
import com.ys.nms.framework.common.pojo.PageParam;
import com.ys.nms.framework.common.util.object.BeanUtils;

import com.ys.nms.module.business.dal.mysql.portsVlans.PortsVlansMapper;

import static com.ys.nms.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.ys.nms.framework.common.util.collection.CollectionUtils.convertList;
import static com.ys.nms.framework.common.util.collection.CollectionUtils.diffList;
import static com.ys.nms.module.business.enums.ErrorCodeConstants.*;

/**
 * ports_vlans Service 实现类
 *
 * @author zzy
 */
@Service
@Validated
public class PortsVlansServiceImpl implements PortsVlansService {

    @Resource
    private PortsVlansMapper portsVlansMapper;

    @Override
    public Integer createPortsVlans(PortsVlansSaveReqVO createReqVO) {
        // 插入
        PortsVlansDO portsVlans = BeanUtils.toBean(createReqVO, PortsVlansDO.class);
        portsVlansMapper.insert(portsVlans);

        // 返回
        return portsVlans.getPortVlanId();
    }

    @Override
    public void updatePortsVlans(PortsVlansSaveReqVO updateReqVO) {
        // 校验存在
        validatePortsVlansExists(updateReqVO.getPortVlanId());
        // 更新
        PortsVlansDO updateObj = BeanUtils.toBean(updateReqVO, PortsVlansDO.class);
        portsVlansMapper.updateById(updateObj);
    }

    @Override
    public void deletePortsVlans(Integer id) {
        // 校验存在
        validatePortsVlansExists(id);
        // 删除
        portsVlansMapper.deleteById(id);
    }

    @Override
        public void deletePortsVlansListByIds(List<Integer> ids) {
        // 删除
        portsVlansMapper.deleteByIds(ids);
        }


    private void validatePortsVlansExists(Integer id) {
        if (portsVlansMapper.selectById(id) == null) {
            throw exception(PORTS_VLANS_NOT_EXISTS);
        }
    }

    @Override
    public PortsVlansDO getPortsVlans(Integer id) {
        return portsVlansMapper.selectById(id);
    }

    @Override
    public PageResult<PortsVlansDO> getPortsVlansPage(PortsVlansPageReqVO pageReqVO) {
        return portsVlansMapper.selectPage(pageReqVO);
    }

}